package com.example.nationmobile;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.apache.http.entity.mime.MultipartEntity;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import com.coe3.data.AllIntent;
import com.coe3.data.Information;

import com.coe3.datahandler.BaseActivity;
import com.coe3.datahandler.HttpConnection;
import com.coe3.datahandler.ParserXMLHandler;
import com.coe3.datahandler.ParserXMLHandler.ElementData;

import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;


import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public class MulActivity extends BaseActivity implements OnClickListener ,OnItemClickListener {

	
	private TextView txt_daytime;
	private FrameLayout Img_home,img_opinion,Img_mul,Img_favorite,Img_setting; 
	
	
	private LinearLayout Laymainmenu,Layvideo,Layphoto,LayCartoon;
	private View list_mul,list_new,lay_datail_photo;
	private int indexView=-1; //,0=listmain,1=vdo,2=photo,3=catoon
	
	//==================ListView======================
	private ListView lstView;
	private OpiListAdapter adapter;
	private ArrayList<HashMap<String, Object>> MyArrList_home;
	private HashMap<String, Object> map_1 = new HashMap<String, Object>();
	private	ProgressDialog mProgressDialog;
	private String URL="http://www.nationmultimedia.com/new/rss/ipad_v2/ipad_vdo.xml";
	
	private  ArrayList<String> List_link_VDO=new ArrayList<String>();
	private  ArrayList<String> List_link_photo=new ArrayList<String>();	
	private  ArrayList<String> List_link_photoDetail=new ArrayList<String>();		

	private AllIntent allintent=new AllIntent(MulActivity.this);
		
	
	
	//============================photo=================================
	private ImageView img_photo_mul;
	private TextView txt_detail;
	
	
	//===========================UIL====================================
	 private ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();
	 private ImageLoader imageLoader = ImageLoader.getInstance();
	 private DisplayImageOptions options;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		
		Log.e("evt", "====================onCreate====================");
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		WindowManager.LayoutParams.FLAG_FULLSCREEN);
	
		setContentView(R.layout.activity_mul);
		//===========================View====================
		setView();
		
		
		
		//===========================UIL=======================
		 options = new DisplayImageOptions.Builder()
			.showStubImage(R.drawable.thumb)
			.showImageForEmptyUri(R.drawable.thumb)
			.showImageOnFail(R.drawable.thumb)
			.cacheInMemory()
			.cacheOnDisc()
			.displayer(new RoundedBitmapDisplayer(5))
			.build();
		initImageLoader(MulActivity.this);
		

		
		//==============Tab=====================
		Img_home=(FrameLayout)findViewById(R.id.Img_home);
		img_opinion=(FrameLayout)findViewById(R.id.Img_opinion);
		Img_mul=(FrameLayout)findViewById(R.id.Img_mul);
		Img_favorite=(FrameLayout)findViewById(R.id.Img_favorite);
		Img_setting =(FrameLayout)findViewById(R.id.Img_setting);
				
		Img_home.setOnClickListener(this);
	    img_opinion.setOnClickListener(this);
		//Img_mul.setOnClickListener(this);
		Img_favorite.setOnClickListener(this);
		Img_setting .setOnClickListener(this);
		
		
		
		//=================layout=====================
		Laymainmenu=(LinearLayout)findViewById(R.id.Laymainmenu);
		Layvideo=(LinearLayout)findViewById(R.id.Layvideo);
		Layphoto=(LinearLayout)findViewById(R.id.Layphoto);
		LayCartoon=(LinearLayout)findViewById(R.id.LayCartoon);
		
		Layvideo.setOnClickListener(this);
		Layphoto.setOnClickListener(this);
		LayCartoon.setOnClickListener(this);
		
		
		//================photo=======================
		img_photo_mul=(ImageView)findViewById(R.id.img_photo_mul);
		txt_detail=(TextView)findViewById(R.id.txt_detail);
		
		
		
		
		if (lstView == null) {
			lstView = (ListView) findViewById(R.id.list_view);
			setProgressBarIndeterminateVisibility(true);
			lstView.setOnItemClickListener(this);
			 //=====================ProgressDialog==========================
	        mProgressDialog = new ProgressDialog(this);
	        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);         
	        mProgressDialog.setMessage("Loading......");                       
	        mProgressDialog.setCancelable(false);  
	        
	        
	      
	        
			
		}
		if (MyArrList_home == null)
			MyArrList_home = new ArrayList<HashMap<String, Object>>();
		
		
		indexView=0;
		SetTime();
	}
	private void SetTime()
	{
		
	    String resultTxt=""+DateFormat.format("MM/dd/yy , h:mmaa", System.currentTimeMillis());
		txt_daytime=(TextView)findViewById(R.id.txt_daytime);
		txt_daytime.setText(resultTxt);
	}
	private void setView()
	{
		
		list_mul=(View)findViewById(R.id.list_mul_lay);
		list_mul.setVisibility(View.VISIBLE);	
		
		list_new=(View)findViewById(R.id.list_new);
		list_new.setVisibility(View.INVISIBLE);	
		
		lay_datail_photo=(View)findViewById(R.id.lay_datail_photo);
		lay_datail_photo.setVisibility(View.INVISIBLE);
	}
	private void Chk_View()
	{
		if(indexView==0)
		{
			list_mul.setVisibility(View.VISIBLE);	
			list_new.setVisibility(View.INVISIBLE);	
			lay_datail_photo.setVisibility(View.INVISIBLE);
		}
		else
			if(indexView==1)
			{
				list_mul.setVisibility(View.INVISIBLE);	
				list_new.setVisibility(View.VISIBLE);	
				lay_datail_photo.setVisibility(View.INVISIBLE);
			}
		else
			if(indexView==2)
			{
			list_mul.setVisibility(View.INVISIBLE);	
			list_new.setVisibility(View.VISIBLE);	
			lay_datail_photo.setVisibility(View.INVISIBLE);
			}
			else
				if(indexView==21)
				{
					list_mul.setVisibility(View.INVISIBLE);	
					list_new.setVisibility(View.INVISIBLE);	
					lay_datail_photo.setVisibility(View.VISIBLE);
				}
		else
						
		if(indexView==3)
		{
			list_mul.setVisibility(View.INVISIBLE);	
			list_new.setVisibility(View.VISIBLE);	
			lay_datail_photo.setVisibility(View.INVISIBLE);
		}
	}
	
	
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.Img_home)
		{
			finish();	
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		
		if(v.getId()==R.id.Img_opinion)
		{
			finish();	
			startActivityForResult(new Intent(MulActivity.this,OpinionActivity.class), 0);
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		
		if(v.getId()==R.id.Img_favorite)
		{
			finish();	
			startActivityForResult(new Intent(MulActivity.this,FavoritesActivity.class), 0);
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		if(v.getId()==R.id.Img_setting)
		{
			finish();	
			startActivityForResult(new Intent(MulActivity.this,SettingActivity.class), 0);
			overridePendingTransition (R.anim.fade_in, R.anim.fade_out);
		}
		
		
		//==========================Layout==========================
		if(v.getId()==R.id.Layvideo)
		{
			MyArrList_home.clear();
			List_link_VDO.clear();
			startConnection_vdo("http://www.nationmultimedia.com/new/rss/ipad_v2/ipad_vdo.xml", "", HttpConnection.GET, -1, null );
	
			indexView=1;
		}
		if(v.getId()==R.id.Layphoto)
		{
			MyArrList_home.clear();
			startConnection_photo("http://www.nationmultimedia.com/new/rss/ipad_v2/photo.xml", "", HttpConnection.GET, -1, null );
		
			indexView=2;
		}
		if(v.getId()==R.id.LayCartoon)
		{
			MyArrList_home.clear();
			startConnection_cartoon("http://www.nationmultimedia.com/new/rss/iphone_v2/opinion_photo.xml", "", HttpConnection.GET, -1, null );
			
	
			indexView=2;
		}
		
		Chk_View();
		
	}
	@Override
	public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
		// TODO Auto-generated method stub
		if(indexView==1)
		{
			allintent.OpenVDO(List_link_VDO.get(position));
			Chk_View();
		}
		if(indexView==2)
		{
			
			
			Log.e("NT","size="+List_link_photo.size()+"");
			try {imageLoader.displayImage(List_link_photo.get(position), img_photo_mul, options, animateFirstListener);}catch (Exception e) {e.printStackTrace();}
			txt_detail.setText(List_link_photoDetail.get(position));
			
			
			indexView=21;
			Chk_View();
			
		}
		
	}
	public boolean onKeyDown( int keyCode, KeyEvent event ) {

	    if ( keyCode == KeyEvent.KEYCODE_BACK ) {
	    	
	    	if(indexView==1||indexView==2)
	    	{
	    		indexView=0;
	    		Chk_View();
				
	    	}
	    	else 
	    		if(indexView==21)
	    		{
	    			indexView=2;
	    			Chk_View();
	    		}
	    		else
	    		finish();
	    	
	    	
	    	return true;
	    }

	    return super.onKeyDown(keyCode, event);
	}
	
	
	
	
			
			
	public void startConnection_vdo( String url, String data , int method, final int handlerType, final MultipartEntity entity ) {
				Log.e("max", "MainActivity==========startConnection");
				Log.e("chud", "url: " + url);
				Log.e("chud", "data: " + data);
				
				Handler handler = new Handler() {
					public void handleMessage(Message message) {
						switch ( message.what ) {
						case HttpConnection.DID_START:
							showDialog( DIALOG_CONNECTION_START );
							break;
						
						case HttpConnection.DID_SUCCEED:
							try {
								Log.e("chud", "(String)message.obj: " + (String)message.obj);
								startParseXMLResponse_vdo( (String)message.obj, handlerType );
							} catch ( Exception e ) {
								Log.e( "Connection Exception", "XML Pasing Excpetion : " + e );
								didFinishParsing();
							}
							
							break;
						
						case HttpConnection.DID_ERROR:
							Log.e( "Connection Error", "HTTP Connection did error : " + message.obj );
							BaseActivity.showAlertBox(getBaseContext(),  "Connection Error!!!", "Please try again." );
							didFinishParsing();
							break;
						}	
					}
				};
				
				HttpConnection connection = new HttpConnection(handler);
				if( entity != null )
					connection.setMultipartEntity( entity );
				connection.create(method, url, data);
			}
	public void startParseXMLResponse_vdo( String response, int handlerType ) throws SAXException, ParserConfigurationException, IOException {
				
				Log.e("max", "MainActivity==========startParseXMLResponse");
				SAXParserFactory spf = SAXParserFactory.newInstance();
				SAXParser sp = spf.newSAXParser();
				XMLReader xr = sp.getXMLReader();
				
				ParserXMLHandler parser = null;
				Handler handler = handlerInformation_vdo(handlerType);
				parser = new ParserXMLHandler( handler );
				
				StringReader sr = new StringReader(response);
				InputSource is = new InputSource(sr);
				
				xr.setContentHandler(parser);
				xr.parse(is);
			}
			
	private static Vector<NewData> mListNews_vdo = new Vector<NewData>();
	private NewData mItem_vdo = null;
			@SuppressLint("HandlerLeak")
	public Handler handlerInformation_vdo(final int handlerType) {
				
				Log.e("max", "MainActivity==========handlerInformation");
				
				Handler mHandler = new Handler() {
					public void handleMessage( Message message ) {
						ElementData data = ( ElementData )message.obj;
						switch( message.what ) {
							case ParserXMLHandler.START_DOCUMENT:
								
								mListNews_vdo.removeAllElements();
								
								break;
								
							case ParserXMLHandler.DID_START_ELEMENT:
								
								if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
								{
									mItem_vdo = new NewData();
								}//end if
								
								if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_URL) ) 
								{
									mItem_vdo.enclosure_url = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_URL), Information.STR_EMPTY);
								}//end if
								
								if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_TYPE) ) {
									mItem_vdo.enclosure_type = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_TYPE), Information.STR_EMPTY);
								}//end if
								
								break;
								
							case ParserXMLHandler.DID_FINISH_ELEMENT:
								
								if( data.name.equalsIgnoreCase(NewData.TAG_TITLE) ) 
								{
									mItem_vdo.title = Information.setData(data.value, Information.STR_EMPTY);
								} 
								else if( data.name.equalsIgnoreCase(NewData.TAG_DESCRIPTION) ) 
								{
									mItem_vdo.description = Information.setData(data.value, Information.STR_EMPTY);
								}
								else if( data.name.equalsIgnoreCase(NewData.TAG_VIDEO) ) 
								{
									mItem_vdo.video = Information.setData(data.value, Information.STR_EMPTY);
								}
								else if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
								{
									mListNews_vdo.add(mItem_vdo);
									mItem_vdo = null;
								}//end if
								
								break;
								
							case ParserXMLHandler.END_DOCUMENT:
								
							
								
								setNews_vdo(mListNews_vdo);
								didFinishParsing();
							 
								break;
						}
					}
				};
					
				return mHandler;
			}
	public void setNews_vdo(Vector<NewData> listNews) {
				
				if (adapter == null) {
					adapter = new OpiListAdapter(MulActivity.this, MyArrList_home);
					lstView.setAdapter(adapter);
				}
				
				Log.e("max", "MainActivity==========setNews(Vector<NewData> listNews)");
				for (NewData newData : listNews) {
					map_1 = new HashMap<String, Object>();
					
					Information.logDEBUG("title: " + newData.title);
					Information.logDEBUG("description: " + newData.description);
					Information.logDEBUG("enclosure_url: " + newData.enclosure_url);
					Information.logDEBUG("enclosure_type: " + newData.enclosure_type);
					Information.logDEBUG("video: " + newData.video);
					
					Log.e("max","enclosure_url="+ newData.enclosure_url);
				
					map_1.put("title", newData.title);
					map_1.put("description", newData.description);
					map_1.put("thumbnail", newData.enclosure_url);
					map_1.put("detail", newData.detail);
					map_1.put("photo", newData.photo);
					List_link_VDO.add(newData.video);
					
					
					MyArrList_home.add(map_1);	
						

					runOnUiThread (new Thread(new Runnable() { 
				         public void run() {
				                adapter.notifyDataSetChanged();    
				               
				         }
				     }));
					 
					 
					
					
				}
			}
			

	
	
	
	public void startConnection_photo( String url, String data , int method, final int handlerType, final MultipartEntity entity ) {
		
		
		Handler handler = new Handler() {
			public void handleMessage(Message message) {
				switch ( message.what ) {
				case HttpConnection.DID_START:
					showDialog( DIALOG_CONNECTION_START );
					break;
				
				case HttpConnection.DID_SUCCEED:
					try {
						Log.e("chud", "(String)message.obj: " + (String)message.obj);
						startParseXMLResponse_photo( (String)message.obj, handlerType );
					} catch ( Exception e ) {
						Log.e( "Connection Exception", "XML Pasing Excpetion : " + e );
						didFinishParsing();
					}
					
					break;
				
				case HttpConnection.DID_ERROR:
					Log.e( "Connection Error", "HTTP Connection did error : " + message.obj );
					BaseActivity.showAlertBox(getBaseContext(),  "Connection Error!!!", "Please try again." );
					didFinishParsing();
					break;
				}	
			}
		};
		
		HttpConnection connection = new HttpConnection(handler);
		if( entity != null )
			connection.setMultipartEntity( entity );
		connection.create(method, url, data);
	}
	public void startParseXMLResponse_photo( String response, int handlerType ) throws SAXException, ParserConfigurationException, IOException {
		
		Log.e("max", "MainActivity==========startParseXMLResponse");
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		XMLReader xr = sp.getXMLReader();
		
		ParserXMLHandler parser = null;
		Handler handler = handlerInformation_photo(handlerType);
		parser = new ParserXMLHandler( handler );
		
		StringReader sr = new StringReader(response);
		InputSource is = new InputSource(sr);
		
		xr.setContentHandler(parser);
		xr.parse(is);
	}
	
	private static Vector<NewData> mListNews_photo = new Vector<NewData>();
	private NewData mItem_photo = null;
	@SuppressLint("HandlerLeak")
	public Handler handlerInformation_photo(final int handlerType) {
		
		Log.e("max", "MainActivity==========handlerInformation");
		
		Handler mHandler = new Handler() {
			public void handleMessage( Message message ) {
				ElementData data = ( ElementData )message.obj;
				switch( message.what ) {
					case ParserXMLHandler.START_DOCUMENT:
						
						mListNews_photo.removeAllElements();
						
						break;
						
					case ParserXMLHandler.DID_START_ELEMENT:
						
						if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
						{
							mItem_photo = new NewData();
						}//end if
						
						if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_URL) ) 
						{
							mItem_photo.enclosure_url = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_URL), Information.STR_EMPTY);
						}//end if
						
						if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_TYPE) ) {
							mItem_photo.enclosure_type = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_TYPE), Information.STR_EMPTY);
						}//end if
						
						break;
						
					case ParserXMLHandler.DID_FINISH_ELEMENT:
						
						if( data.name.equalsIgnoreCase(NewData.TAG_TITLE) ) 
						{
							mItem_photo.title = Information.setData(data.value, Information.STR_EMPTY);
						} 
						else if( data.name.equalsIgnoreCase(NewData.TAG_DESCRIPTION) ) 
						{
							mItem_photo.description = Information.setData(data.value, Information.STR_EMPTY);
						}
						else if( data.name.equalsIgnoreCase(NewData.TAG_VIDEO) ) 
						{
							mItem_photo.video = Information.setData(data.value, Information.STR_EMPTY);
						}
						else if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
						{
							mListNews_photo.add(mItem_photo);
							mItem_photo = null;
						}//end if
						
						break;
						
					case ParserXMLHandler.END_DOCUMENT:
						
					
						
						setNews_photo(mListNews_photo);
						didFinishParsing();
					 
						break;
				}
			}
		};
			
		return mHandler;
	}
	public void setNews_photo(Vector<NewData> listNews) {
		
		if (adapter == null) {
			adapter = new OpiListAdapter(MulActivity.this, MyArrList_home);
			lstView.setAdapter(adapter);
		}
		
		Log.e("max", "setNews_photo");
		for (NewData newData : listNews) {
			map_1 = new HashMap<String, Object>();
			
		
			List_link_photo.add(newData.enclosure_url);
			List_link_photoDetail.add(newData.description);
			//Log.e("max","List_link_photo.size()="+ List_link_photo.size());
			map_1.put("title", newData.title);
			map_1.put("description", newData.description);
			map_1.put("thumbnail", newData.enclosure_url);
			map_1.put("detail", newData.detail);
			map_1.put("photo", newData.photo);
		
			
			
			MyArrList_home.add(map_1);	
				

			runOnUiThread (new Thread(new Runnable() { 
		         public void run() {
		                adapter.notifyDataSetChanged();    
		               
		         }
		     }));
			 
			 
			
			Log.e("NT","size="+List_link_photo.size()+"");
		}
	}
			
			
	public void startConnection_cartoon( String url, String data , int method, final int handlerType, final MultipartEntity entity ) {
		
		
		Handler handler = new Handler() {
			public void handleMessage(Message message) {
				switch ( message.what ) {
				case HttpConnection.DID_START:
					showDialog( DIALOG_CONNECTION_START );
					break;
				
				case HttpConnection.DID_SUCCEED:
					try {
						Log.e("chud", "(String)message.obj: " + (String)message.obj);
						startParseXMLResponse_cartoon( (String)message.obj, handlerType );
					} catch ( Exception e ) {
						Log.e( "Connection Exception", "XML Pasing Excpetion : " + e );
						didFinishParsing();
					}
					
					break;
				
				case HttpConnection.DID_ERROR:
					Log.e( "Connection Error", "HTTP Connection did error : " + message.obj );
					BaseActivity.showAlertBox(getBaseContext(),  "Connection Error!!!", "Please try again." );
					didFinishParsing();
					break;
				}	
			}
		};
		
		HttpConnection connection = new HttpConnection(handler);
		if( entity != null )
			connection.setMultipartEntity( entity );
		connection.create(method, url, data);
	}
	public void startParseXMLResponse_cartoon( String response, int handlerType ) throws SAXException, ParserConfigurationException, IOException {
		
		Log.e("max", "MainActivity==========startParseXMLResponse");
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = spf.newSAXParser();
		XMLReader xr = sp.getXMLReader();
		
		ParserXMLHandler parser = null;
		Handler handler = handlerInformation_cartoon(handlerType);
		parser = new ParserXMLHandler( handler );
		
		StringReader sr = new StringReader(response);
		InputSource is = new InputSource(sr);
		
		xr.setContentHandler(parser);
		xr.parse(is);
	}
	
	private static Vector<NewData> mListNews_cartoon = new Vector<NewData>();
	private NewData mItem_cartoon = null;
	@SuppressLint("HandlerLeak")
	public Handler handlerInformation_cartoon(final int handlerType) {
		
		Log.e("max", "MainActivity==========handlerInformation");
		
		Handler mHandler = new Handler() {
			public void handleMessage( Message message ) {
				ElementData data = ( ElementData )message.obj;
				switch( message.what ) {
					case ParserXMLHandler.START_DOCUMENT:
						
						mListNews_cartoon.removeAllElements();
						
						break;
						
					case ParserXMLHandler.DID_START_ELEMENT:
						
						if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
						{
							mItem_cartoon = new NewData();
						}//end if
						
						if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_URL) ) 
						{
							mItem_cartoon.enclosure_url = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_URL), Information.STR_EMPTY);
						}//end if
						
						if( data.attributes.containsKey(NewData.TAG_ENCLOSURE_TYPE) ) {
							mItem_cartoon.enclosure_type = Information.setData(data.attributes.get(NewData.TAG_ENCLOSURE_TYPE), Information.STR_EMPTY);
						}//end if
						
						break;
						
					case ParserXMLHandler.DID_FINISH_ELEMENT:
						
						if( data.name.equalsIgnoreCase(NewData.TAG_PUBDate) ) 
						{
							mItem_cartoon.title = Information.setData(data.value, Information.STR_EMPTY);
						} 
						else if( data.name.equalsIgnoreCase(NewData.TAG_DESCRIPTION) ) 
						{
							mItem_cartoon.description = Information.setData(data.value, Information.STR_EMPTY);
						}
						else if( data.name.equalsIgnoreCase(NewData.TAG_VIDEO) ) 
						{
							mItem_cartoon.video = Information.setData(data.value, Information.STR_EMPTY);
						}
						else if( data.name.equalsIgnoreCase(NewData.TAG_ITEM) ) 
						{
							mListNews_cartoon.add(mItem_cartoon);
							mItem_cartoon = null;
						}//end if
						
						break;
						
					case ParserXMLHandler.END_DOCUMENT:
						
					
						
						setNews_cartoon(mListNews_cartoon);
						didFinishParsing();
					 
						break;
				}
			}
		};
			
		return mHandler;
	}
	public void setNews_cartoon(Vector<NewData> listNews) {
		
		if (adapter == null) {
			adapter = new OpiListAdapter(MulActivity.this, MyArrList_home);
			lstView.setAdapter(adapter);
		}
		
		Log.e("max", "setNews_cartoon(");
		for (NewData newData : listNews) {
			map_1 = new HashMap<String, Object>();
			
		Log.e("NT","newData.title="+newData.title+"");
			
			List_link_photo.add(newData.enclosure_url);
			List_link_photoDetail.add(newData.description);
			//Log.e("max","List_link_photo.size()="+ List_link_photo.size());
			map_1.put("title", newData.title);
			map_1.put("description", newData.description);
			map_1.put("thumbnail", newData.enclosure_url);
			map_1.put("detail", newData.detail);
			map_1.put("photo", newData.photo);
		
			
			MyArrList_home.add(map_1);	
				

			runOnUiThread (new Thread(new Runnable() { 
		         public void run() {
		                adapter.notifyDataSetChanged();    
		               
		         }
		     }));
			 
			 
			
			
		}
	}
			
	
    
			
	
	
	//============================UIL=================================
	 public static void initImageLoader(Context context) {
	  		// This configuration tuning is custom. You can tune every option, you may tune some of them, 
	  		// or you can create default configuration by
	  		//  ImageLoaderConfiguration.createDefault(this);
	  		// method.
	  		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
			  		.memoryCacheExtraOptions(600, 800) // default = device screen dimensions
			        .threadPoolSize(3) // default
			        .threadPriority(Thread.NORM_PRIORITY - 1) // default
			        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
			        .denyCacheImageMultipleSizesInMemory()
			        .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
			        .memoryCacheSize(2 * 1024 * 1024)
			        .discCacheSize(50 * 1024 * 1024)
			        .discCacheFileCount(100)
			        .discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
			        .imageDownloader(new BaseImageDownloader(context)) // default
			        .imageDecoder(new BaseImageDecoder()) // default
			        .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
			        .build();
	  		// Initialize ImageLoader with configuration.
	  		ImageLoader.getInstance().init(config);
	  	}
	  	
	    
	  	@SuppressWarnings("unused")
	 private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {

			static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());

			@Override
			public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
				if (loadedImage != null) {
					ImageView imageView = (ImageView) view;
					boolean firstDisplay = !displayedImages.contains(imageUri);
					if (firstDisplay) {
						FadeInBitmapDisplayer.animate(imageView, 500);
						displayedImages.add(imageUri);
					}
				}
			}
		}
	    
			
}
